import {getDoneTaskList,withdraw} from '@/api/api.js'
import PageTemplate from '@/components/common/PageTemplate'
import api_home from '@/api/api_home'
import * as Constant from '@/utils/constant'
export default {
    components:{
      PageTemplate
    },
    data(){
        return {
            hasIcon:false,
            advSearch:'adt.advance_search',
            task_des_com:'',
            flow_name:'',
            task_des:'',
            launch_time:'',
            procPicUrl:process.env.PROCPIC_ROOT,
            pageSize:10,
            pageIndex:1,
            total:0,
            searchType:0,
            searchParam:{},
            tables:[

            ],
            processRouterMap: {
              "SWP-SU\\pur_demIn": {
                "020_队办经理审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHIN_DET.index,
                "030_计划协调员审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHIN_DET.index,
                "040_调试采购主管审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHIN_DET.index
              },
              "SWP-SU\\pur_demOut": {
                "020_队办经理审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHOUT_DET.index,
                "030_计划协调员审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHOUT_DET.index,
                "040_调试采购主管审批": Constant.ROUTE_PUR_PROCESS_DEM_WITHOUT_DET.index
              },
              "SWP-SU\\pur_demChange": {
                "010_需求人提交年度采购需求": Constant.ROUTE_PUR_PROCESS_DEM_CHANGE_DET.index,
                "020_队办经理审批": Constant.ROUTE_PUR_PROCESS_DEM_CHANGE_DET.index,
                "030_计划协调员审批": Constant.ROUTE_PUR_PROCESS_DEM_CHANGE_DET.index,
                "040_调试采购主管审批": Constant.ROUTE_PUR_PROCESS_DEM_CHANGE_DET.index
              },
              "SWP-SU\\pur_demClose": {
                "020_计划协调员审批": Constant.ROUTE_PUR_PROCESS_DEM_CLOSE_DET.index,
                "030_调试采购主管审批": Constant.ROUTE_PUR_PROCESS_DEM_CLOSE_DET.index,
                "040_调试采购主管审批": Constant.ROUTE_PUR_PROCESS_DEM_CLOSE_DET.index
              },
              "SWP-SU\\sci_thesis": {
                  "010_提交论文": Constant.ROUTE_SRI_GAIN_THESIS_DONE.index,
                  "020_论文管理员审批": Constant.ROUTE_SRI_GAIN_THESIS_DONE.index
              },
              "SWP-SU\\sci_budget": {
                  "010_提交预算申请": Constant.ROUTE_SRI_BUDGET_DONE.index,
                  "020_预算管理员审批": Constant.ROUTE_SRI_BUDGET_DONE.index
              },
              "SWP-SU\\sci_cbpPlan": {
                  "010_提交能力建设年度工作计划": Constant.ROUTE_SRI_GAIN_CBP_PLAN_DONE.index,
                  "020_专业分部协调员审批": Constant.ROUTE_SRI_GAIN_CBP_PLAN_DONE.index,
                  "030_能力建设管理工程师审批": Constant.ROUTE_SRI_GAIN_CBP_PLAN_DONE.index,
                  "040_主任或副主任审批": Constant.ROUTE_SRI_GAIN_CBP_PLAN_DONE.index,
              },
              "SWP-SU\\sci_cbpProcess" :{
                  "010_项目负责人提交能建计划进展": Constant.ROUTE_SRI_GAIN_CBP_PROGRESS_DONE.index,
                  "020_能力建设管理工程师审批": Constant.ROUTE_SRI_GAIN_CBP_PROGRESS_DONE.index,
              },
              "SWP-SU\\sri_alpPlan" :{
                  "010_提交实验室年度工作计划": Constant.ROUTE_SRI_GAIN_ALP_PLAN_DONE.index,
                  "020_实验室专家": Constant.ROUTE_SRI_GAIN_ALP_PLAN_DONE.index,
                  "030_主任或副主任审批": Constant.ROUTE_SRI_GAIN_ALP_PLAN_DONE.index,
              },
              "SWP-SU\\sri_alpProcess" :{
                  "010_项目负责人提交工作进展": Constant.ROUTE_SRI_GAIN_ALP_PROGRESS_DONE.index,
                  "020_实验室专家": Constant.ROUTE_SRI_GAIN_ALP_PROGRESS_DONE.index,
                  "030_主任或副主任审批": Constant.ROUTE_SRI_GAIN_ALP_PROGRESS_DONE.index,
              },
              "SWP-SU\\hr_backApproval":{
                  "010_编制人员调配计划": Constant.ROUTE_HR_BACK_DONE.index,
                  "020_队办经理审批": Constant.ROUTE_HR_BACK_DONE.index,
                  "030_SAM归档": Constant.ROUTE_HR_BACK_DONE.index,
              },
              "SWP-SU\\hr_frontApproval":{
                  "010_编制人员岗位需求": Constant.ROUTE_HR_FONT_DONE.index,
                  "020_队办经理审批": Constant.ROUTE_HR_FONT_DONE.index,
                  "030_分部经理审批": Constant.ROUTE_HR_FONT_DONE.index,
                  "040_专业工程师审批": Constant.ROUTE_HR_FONT_DONE.index,
                  "050_专业部门处长审批": Constant.ROUTE_HR_FONT_DONE.index,
                  "060_SPB成本审批": Constant.ROUTE_HR_FONT_DONE.index,
                  "070_SMB归档": Constant.ROUTE_HR_FONT_DONE.index,
              },
          }
        }
    },
    methods:{
      advanceSearch : function(){
        if(this.advSearch == "adt.advance_search"){
          this.advSearch = "adt.return";
        }else{
          this.advSearch = "adt.advance_search";
        }
      },
      toDetails:function(item){
        // this.$router.push({path:"/already_done_task_details/"+row.procInstID,query:{obj:row}});
        console.log("异常调试信息===103==already_done_task.js==："+item.data)
        console.log("===104==already_done_task.js==："+this.processRouterMap)
        let _this = this;
        // item.formInstID = item.fromNO
        // item.actName
        if(this.processRouterMap[item.processFullName][item.actName]) {
          api_home.updateVisitTime({processFullName: item.processFullName, processName: item.processName}, response => {
          })
            setTimeout(()=>{
              _this.$router.push({path:this.processRouterMap[item.processFullName][item.actName],query:{obj:item}});
            }, 2000)
        }else{
            _this.$alert("please check processRouterMap.");
        }
      },

      //重置操作
      reset:function(){
        this.flow_name = "";
        this.task_des = "";
        this.launch_time = null;
      },
      //关于翻页操作的都在下面的方法中，所有的可以copy这里的方法过去.

      //统一与后台操作的方法
      showTableList:function(params){
        //这里的params是对象
        //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
        let _this = this;
        _this.tables = [];
        getDoneTaskList(params).then((result) => {

          if(result.status == "200" && result.data.code=="0"){
            let data = result.data.data.data;
            //表格数据  数组
            _this.tables = data.resultData;
            //分页数据
            _this.pageSize = data.page.pageSize;
            _this.pageIndex = data.page.startPage;
            _this.total = data.page.totalCount;
          }else{
            _this.$alert(result.data.msg,_this.$t('cm.tips'));
          }

        }).catch((err) => {
          _this.$alert(err,_this.$t('cm.tips'));
        });

      },
      //其他的方法  统一设置好  param  再调用 showTableList方法与后台交互
      commonSearch:function(){
        let params= {
          searchType:1,
          taskDes:this.task_des_com,
          //这块可以分离出去  再合并 merge
          pageSize:this.pageSize,
          pageIndex:this.pageIndex,
          t:Math.random(),
        }
        this.searchType=1;
        this.searchParam = {
          taskDes:this.task_des_com,
        };
        this.showTableList(params);
      },
      advSearchs:function(){

        this.searchType = 2;
        let params = {
          processName:this.flow_name,
          taskDes:this.task_des,
          launchTime:this.launch_time,
          pageSize:this.pageSize,
          pageIndex:this.pageIndex,
          t:Math.random(),
          searchType:this.searchType
        }
        this.searchParam = {
          processName:this.flow_name,
          taskDes:this.task_des,
          launchTime:this.launch_time,
        };
        this.showTableList(params);
      },
      nextPage:function(nowPage){
        let params = {
          pageSize:this.pageSize= this.pageSize+1,
          pageIndex:this.pageIndex,
          t:Math.random(),
          searchType:this.searchType,
        }
        params = Object.assign(params,this.searchParam);
        this.showTableList(params);
      },
      lastPage:function(nowPage){
        let params= {
          pageSize:this.pageSize = this.pageSize-1,
          pageIndex:this.pageIndex,
          t:Math.random(),
          searchType:this.searchType,
        }
        params = Object.assign(params,this.searchParam);
        this.showTableList(params);
      },
      selectPage:function(nowPage){
        let params= {
          pageSize:this.pageSize,
          pageIndex:this.pageIndex = nowPage,
          t:Math.random(),
          searchType:this.searchType,
        }
        params = Object.assign(params,this.searchParam);
        this.showTableList(params);
      },
      selectPageSize:function(pageSize){
        let params= {
          pageSize:this.pageSize = pageSize,
          pageIndex:this.pageIndex,
          t:Math.random(),
          searchType:this.searchType,
        }
        params = Object.assign(params,this.searchParam);
        this.showTableList(params);
      },
      //
      transName:function(row,col,val){
        return "["+row.startUser+"]"+row.startCNUser+"("+row.status+")";
      },
      showProcPic:function(row){
        //展示流程图
        window.open(this.procPicUrl+row.procInstID);
      },
      //撤回流程
      withdrawProc:function(row){
        let _this = this;
        withdraw({procInstId:row.procInstID}).then((result) => {
          if(result.status == "200" && result.data.code == "0"){
            if(result.data.data.data != null){
              _this.$alert(result.data.data.data,_this.$t('cm.tips'),{
                callback: _=>{

                }
              })
            }else{
              //刷新当前页面
              _this.initList();
            }
          }else{
            _this.$alert(result.data.msg,_this.$t('cm.tips'));
          }
        }).catch((err) => {
          _this.$alert(err,_this.$t('cm.tips'));
        });
      },
      initList:function(){
        let params = {
          searchType:0,
          pageSize:this.pageSize,
          pageIndex:1,
          t:Math.random(),
        }
        this.showTableList(params);
      }
    },
    mounted() {
      //初始化列表 填充tables
      let params = {
        searchType:0,
        pageSize:this.pageSize,
        pageIndex:this.pageIndex,
        t:Math.random(),
      }
      this.showTableList(params);
    },
}
